package cc.yugu.yhdw.webserver.service.hdw;

import cc.yugu.yhdw.common.domain.hdw.AgencyDeductMoney;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.pagination.Page;
import cc.yugu.yhdw.webserver.persistence.hdw.AgencyDeductMoneyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
/**
 * 代理商扣款记录业务
 * 
 * @Date:Created in 2018/7/5 16:03
 * @Author:
 * @Modified By: zjn 2018/7/5 16:03
 */ 
@Service
public class AgencyDeductMoneyService {

    @Autowired
    AgencyDeductMoneyMapper agencyDeductMoneyMapper;

    public AgencyDeductMoney find(int id) {
        return agencyDeductMoneyMapper.find(id);
    }
    /**
    * 分页查询
    * 
    * @Param: [search]
    * @Return: cc.yugu.yhdw.common.entity.pagination.Page
    * @Author By: zjn 2018/7/5  16:04
    */ 
    public Page findPage(AgencyDeductMoney search) {
        Page page = search.buildPage();
        page.setTotalItems(agencyDeductMoneyMapper.findPageCount(search));
        search.setBeginIndex(page.getOffset());
        page.setResult(agencyDeductMoneyMapper.findPageResult(search));
        return page;
    }
    /**
    * 插入
    * 
    * @Param: [supplier]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/5  16:04
    */ 
    public ExtResult insert(AgencyDeductMoney supplier) {
        try {
            supplier.setCreateTime(new Date());
            agencyDeductMoneyMapper.insert(supplier);
        } catch (Exception e) {
            return ExtResult.failResult("操作失败");
        }
        return ExtResult.successResult();
    }
    /**
    * 根据主键更新
    * 
    * @Param: [entity]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/5  16:04
    */ 
    public ExtResult update(AgencyDeductMoney entity) {
        try {
            agencyDeductMoneyMapper.update(entity);
        } catch (Exception e) {
            return ExtResult.failResult("操作失败");
        }
        return ExtResult.successResult();
    }
    /**
    * 根据主键删除
    * 
    * @Param: [id]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/5  16:05
    */ 
    public ExtResult delete(int id) {
        try {
            agencyDeductMoneyMapper.delete(id);
        } catch (Exception e) {
            return ExtResult.failResult("操作失败");
        }
        return ExtResult.successResult();
    }
}
